
<TABLE class="overheaddisplay" border=1 cellspacing=0>
<?php
	$startD=$current_day;	
	$startDate=$year.'-'.$month.'-'.$current_day;
	$endM=$month;
	$endY=$year;
	$endDay=$current_day+1;
	
	if ($endDay>cal_days_in_month(0,$month,$year)){
		$endM++;
		if ($endM%13==0){
			$endM=1;
			$endY++;
		}
		$endDay=1;
	}
	//$startDate=$year."-".$month."-".$startD;	
	//$endDate=$endY."-".$endM."-".$endDay;
	//$events=outputCalendarByDateRange($client, $startDate, $endDate);
	$hours=array();
	foreach($events as $event){	
		$eventWhenArray=$event->when;		
		foreach($eventWhenArray as $eventWhen){
			if (substr($eventWhen,16,2)==$startD){
				$eHour=substr($eventWhen,19,2);
				$fHour = substr($eventWhen,55,2) - 1;
				if (substr($eHour,0,1)=="0") {
					$eHour=substr($eHour,1,1);
				}
				if (substr($fHour,0,1)=="0") {
					$fHour=substr($fHour,1,1);
				}
			$var='T';
			if (strpos($eventWhen,$var)){
				while ($eHour<=$fHour) {
					$hours[$eHour][] = $event;
					$eHour++;
				}
				//$hours[$eHour][]=$event;
			}
			else {
				$hours[25][]=$event;
			}
			}
		}
	}

	
      	echo "</P></font></TD></TR></TABLE>";

	echo "<DIV id='printOverflow'>";
	echo "<TABLE class='daydisplay' border=1 cellspacing=0>";

	echo "<TR><TD width=80 height=80 align=right class='alldaydisplay'>";
	echo "<font size=2><B>All Day: </B></font>";
	echo "</TD><TD height=30 valign=top><P><font size=2><DIV id='whiteFont'>";
	if (count($hours[25])>0) {
		foreach($hours[25] as $allDayEvent){
			echo "<li class='".$allDayEvent->calColor."' style='background-color:".$allDayEvent->calColor."; filter:alpha(opacity=83);-moz-opacity:.83;opacity:.83; margin:0px; cursor:default; height:15px; padding-top:2px'><a style='cursor:default' onclick='editEvent(".$json->encode($allDayEvent).")'>".$allDayEvent->title." : ".$allDayEvent->desc." : ".$allDayEvent->place."</a></li>";
			//echo "<li>".$allDayEvent->title."</li>";
		}
	}
echo "</P></DIV></font></TD></TR>";


	for ($hour=0; $hour<=24; $hour++) {
		if ($hour == 0) {
			$displayHour = 12;
			$am = true;
		}
		else if ($hour < 12 || $hour == 24) {
			$displayHour=$hour;
			$am = true;
			if ($displayHour==24){
				$displayHour=$hour/2;
			}
		}
		else {
			$displayHour=$hour-12;

			if ($displayHour==0){
				$displayHour=12;
			}
			$am = false;
		}
		if ($hour == 5)
			echo "<TR><TD width=80 align=right class='hourdisplay' valign=top>$displayHour<a name='startDisplay'></a>";
		else
			echo "<TR><TD width=80 align=right class='hourdisplay' valign=top>$displayHour";
		if ($am)
			echo ":00 am&nbsp;";
		else
			echo ":00 pm&nbsp;";
		echo "</TD>";
		$set=0;
		if (count($hours[$hour])==0){
			echo "<TD height=30 class='eventDisplay'>";
			$set=0;
		} else {
			echo "<TD height=30><DIV id='whiteFont'>";
			$set=1;
		}
		echo "<font size='2'>";
		if ($set==1){
			foreach ($hours[$hour] as $event){
				echo "<bgcolor='silver'>";
				echo "<li class='".$event->calColor."' style='background-color:".$event->calColor."; filter:alpha(opacity=83);-moz-opacity:.83;opacity:.83; margin:0px; cursor:default; height:20px; padding-top:5px'><a style='cursor:default' onclick='editEvent(".$json->encode($event).")'>".$event->title." : ".$event->desc." : ".$event->place."</a></li>";
			}
       /*  		
			$eHour=substr($eventWhen,19,2);
			$eMin=substr($eventWhen,22,2);
                        if (substr($eHour,0,1)=="0"){
                                $eHour=substr($eHour,1,1);
                        }
                        echo $eHour.":".$eMin." ".$event->title."<br>";*/

		$set=0;}
		echo "</font>";
		echo "</DIV></TD></TR>";
	}
?>
</TABLE>
</DIV>
